using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CodeStory.Core.UI;
using Activa.CoolStorage;
using CodeStory.Core.ObjectEntity;

namespace CodeStory.WebApplication.Modules.Core.Admin
{
	public partial class NoteManager : Portlet
	{
		protected override void OnInit(EventArgs e) {
			Load += new EventHandler(NoteManager_Load);
			gvNotes.RowCommand += new GridViewCommandEventHandler(GridViewNotes_RowCommand);
			base.OnInit(e);
		}

		void GridViewNotes_RowCommand(object sender, GridViewCommandEventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			switch (e.CommandName) {
				case "Delete":
					DeleteNote(e.CommandArgument);
					break;
			}
			BindNotes();
		}

		private void DeleteNote(object noteid) {
			Guid id = new Guid(noteid.ToString());
			NoteObject obj = NoteObject.Read(id);
			obj.Delete();
		}

		void NoteManager_Load(object sender, EventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			if (!IsPostBack) {
				BindNotes();
			}
		}

		private void BindNotes() {
			CSList<NoteObject> list = NoteObject.List();
			gvNotes.DataSource = list;
			gvNotes.DataBind();
		}
	}
}